var nameLine = [];
var valueLine = [];
var orderList = [];
var pageSet = {};
$(function() {
    search(this);
});

function search() {
    var myChart = echarts.init(document.getElementById('sevenBroken'));
    var myDate = new Date();
    this.orderList = [{'CODE':'G20191010009','DATE':myDate.toLocaleString(),'TIME':myDate.toLocaleString(),'QT_STATUS':'准备就绪'},
        {'CODE':'G20191010008','DATE':myDate.toLocaleString(),'TIME':myDate.toLocaleString(),'QT_STATUS':'准备就绪'},
        {'CODE':'G20191010007','DATE':myDate.toLocaleString(),'TIME':myDate.toLocaleString(),'QT_STATUS':'准备就绪'},
        {'CODE':'G20191010006','DATE':myDate.toLocaleString(),'TIME':myDate.toLocaleString(),'QT_STATUS':'准备就绪'},
        {'CODE':'G20191010005','DATE':myDate.toLocaleString(),'TIME':myDate.toLocaleString(),'QT_STATUS':'准备就绪'}];
    renderTable(this.orderList);
    this.sevenData = [{
        'DATA': myDate.toLocaleDateString(),
        'QTY': '600',
        'HGQTY': '598',
        'BHGQTY': '2',
        'BHGBL': '0.33%'
    },
        {'DATA': myDate.toLocaleDateString(), 'QTY': '700', 'HGQTY': '695', 'BHGQTY': '5', 'BHGBL': '0.71%'},
        {'DATA': myDate.toLocaleDateString(), 'QTY': '650', 'HGQTY': '650', 'BHGQTY': '0', 'BHGBL': '0.00%'},
        {'DATA': myDate.toLocaleDateString(), 'QTY': '600', 'HGQTY': '598', 'BHGQTY': '2', 'BHGBL': '0.33%'},
        {'DATA': myDate.toLocaleDateString(), 'QTY': '700', 'HGQTY': '695', 'BHGQTY': '5', 'BHGBL': '0.71%'},
        {'DATA': myDate.toLocaleDateString(), 'QTY': '650', 'HGQTY': '650', 'BHGQTY': '0', 'BHGBL': '0.00%'},
        {'DATA': myDate.toLocaleDateString(), 'QTY': '650', 'HGQTY': '650', 'BHGQTY': '0', 'BHGBL': '0.00%'}];
    sevenTable(this.sevenData);
    this.ycqkData = [
        {'DATA': '机台1', 'YCYY': '断纱线', 'DATE': myDate.toLocaleString(), 'STATUS': '待处理'},
        {'DATA': '机台2', 'YCYY': '电机故障', 'DATE': myDate.toLocaleString(), 'STATUS': '处理中'},
        {'DATA': '机台3', 'YCYY': '电机故障', 'DATE': myDate.toLocaleString(), 'STATUS': '维修中'},
        {'DATA': '机台4', 'YCYY': '断纱线', 'DATE': myDate.toLocaleString(), 'STATUS': '待处理'}];
    ycqkTable(this.ycqkData);

    this.colsBroken = [{"NAME":'20190921',"VALUE":'0.04'},
        {"NAME":'20190922',"VALUE":'0.54'},
        {"NAME":'20190923',"VALUE":'0.1'},
        {"NAME":'20190924',"VALUE":'0.3'},
        {"NAME":'20190925',"VALUE":'0.4'},
        {"NAME":'20190926',"VALUE":'0.5'},
        {"NAME":'20190927',"VALUE":'0.9'}];
    sevenBroken(myChart,this.colsBroken);
  /*  $.post("<%=request.getContextPath()%>/productLine/search", data, function(res) {
        if(res.result) {
            var myChart = echarts.init(document.getElementById('sevenBroken'));
            pageSet = res.data;
            this.orderList = pageSet.fzjdata.proJobList;//获取作业工单列表数据
            this.sevenData = pageSet.fzjdata.proSevenList;//获取七日产能情况列表
            this.ycqkData = pageSet.fzjdata.proExceptionList;//获取异常情况汇报
            this.colsBroken = pageSet.fzjdata.proSevenLvList; //获取七日不合格率趋势
            this.proSevenStatusList = pageSet.fzjdata.proSevenStatusList; //获取每个机台的状态
            renderTable(this.orderList);
            sevenTable(this.sevenData);
            ycqkTable(this.ycqkData);
            sevenBroken(myChart,this.colsBroken);
        } else {
            alert(res.msg);
        }
    }, "json");*/
}
function renderTable(orderList){
    if(orderList){
        var trHtml = [];
        for(var i in orderList) {
            trHtml.push("<tr>");
            trHtml.push("<td align='center' class='addTr_title'>" + orderList[i].CODE + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + orderList[i].DATE + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + orderList[i].TIME + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + orderList[i].QT_STATUS + "</td>");
            trHtml.push("</tr>");
        }
        trHtml = trHtml.join("");

        $("#addTr").after(trHtml);
    }
}


function sevenTable(sevenData) {
    if(sevenData){
        var trHtml = [];
        for(var i in sevenData) {
            trHtml.push("<tr>");
            trHtml.push("<td align='center' class='addTr_title'>" + sevenData[i].DATA + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + sevenData[i].QTY + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + sevenData[i].HGQTY + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + sevenData[i].BHGQTY + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + sevenData[i].BHGBL + "</td>");
            trHtml.push("</tr>");
        }
        trHtml = trHtml.join("");

        $("#addTrSd").after(trHtml);
    }
    /*layui.use('table', function () {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#sevenDate'
            ,width:550
            ,height: 210
            , skin: 'nob'
            , cols: [[
                {type: 'numbers', fixed: 'left', title: '序号'}
                , {field: 'DATA', title: '日期', align: 'center'}
                , {field: 'QTY', title: '产量', align: 'center'}
                , {field: 'HGQTY', title: '合格数', align: 'center'}
                , {field: 'BHGQTY', title: '不合格数', align: 'center'}
                , {field: 'BHGBL', title: '不合格占比', align: 'center'}
            ]]
            , id: 'sevenDate'
            , data: sevenData
            , page: false
            ,done: function(res, curr, count){
                for(var i=0;i<$('tr').length;i++){
                   $('tr')[i].style.height="15";
                }
            }

        });
    })*/
}

function ycqkTable(ycqkData) {

    if(ycqkData){
        var trHtml = [];
        for(var i in ycqkData) {
            trHtml.push("<tr>");
            trHtml.push("<td align='center' class='addTr_title'>" + ycqkData[i].DATA + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + ycqkData[i].YCYY + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + ycqkData[i].DATE + "</td>");
            trHtml.push("<td align='center' class='addTr_title'>" + ycqkData[i].STATUS + "</td>");
            trHtml.push("</tr>");
        }
        trHtml = trHtml.join("");

        $("#addTrYc").after(trHtml);
    }
    /*layui.use('table', function () {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#ycqkDate'
            , skin: 'nob'
            , cols: [[
                {type: 'numbers', fixed: 'left', title: '序号', height: 10}
                , {field: 'DATA', title: '机台八', align: 'center', height: 10}
                , {field: 'QTY', title: '异常原因', align: 'center', height: 10}
                , {field: 'HGQTY', title: '上报时间', align: 'center', height: 10}
                , {field: 'BHGQTY', title: '状态', align: 'center', height: 10}
            ]]
            , id: 'ycqkDate'
            , data: ycqkData
            , page: false
            , size: 10

        });
    })*/
}


    function sevenBroken(id, data) {
        for(var i in data){
            nameLine.push(data[i].NAME);
            valueLine.push(data[i].VALUE);
        }
        option = {
            xAxis: {
                type: 'category',
                data: nameLine
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: valueLine,
                type: 'line'
            }]
        };
    id.setOption(option);
}
